package com.wanglei.rdd.transform

import org.apache.spark.{SparkConf, SparkContext}

object Spark01_map {

  def main(args: Array[String]): Unit = {

    //
    val conf = new SparkConf().setMaster("local[2]").setAppName("map")
    val sc = new SparkContext(conf)

    // map
    val rdd = sc.makeRDD(List(1, 2, 3, 4), 2)
    rdd.map(_ * 2).collect().foreach(println)

    // mapPartition
    rdd.mapPartitions(
      iter => {
        iter.map(_ * 2)
      }
    ).collect().foreach(println)

    // mapPartitionsWithIndex
    rdd.mapPartitionsWithIndex(
      (idx, iter) => {
        println("idx=" + idx)
        iter.map(_ * 2)
      }
    )

    //
    sc.stop()

  }

}
